﻿using OASystem.BLL.IService;
using OASystem.Model;
using OASystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace OASystem.Controllers
{
    public class FileListController : Controller
    {
        private IFileListService FileList;
        public FileListController(IFileListService fileListService)
        {
            FileList = fileListService;
        }
        // GET: FileList
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult Show(int page,int limit,string FileName,string FileFormat)
        {
            PageListResult<Filelist> pageListResult = new PageListResult<Filelist>();
            pageListResult.code = 0;
            pageListResult.msg = string.Empty;
            List<Function> loginInfos = new List<Function>();
            Expression<Func<Filelist, bool>> whereLambda;
            Expression<Func<Filelist, int>> orderbyLambda;
            if (FileName == null && FileFormat == null)
            {
                whereLambda = a => a.MyFileId == FileData.FileId;
                orderbyLambda = a => a.FileId;
            }else if (FileName != "" && FileFormat == "")
            {
                whereLambda = a => a.MyFileId == FileData.FileId&&a.FileName==FileName;
                orderbyLambda = a => a.FileId;
            }else if (FileName == "" && FileFormat != "")
            {
                whereLambda = a => a.MyFileId == FileData.FileId && a.FileFormat == FileFormat;
                orderbyLambda = a => a.FileId;
            }
            else
            {
                whereLambda = a => a.MyFileId == FileData.FileId && a.FileFormat == FileFormat&& a.FileName == FileName;
                orderbyLambda = a => a.FileId;
            }
            int count = 0;
            pageListResult.data = FileList.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            pageListResult.count = count;
            return Json(pageListResult, JsonRequestBehavior.AllowGet);
        }
        public JsonResult DelFile(Filelist fileList)
        {
            Operate operate = new Operate();
            operate.Success = FileList.Delete(fileList);
            return Json(operate);
        }
    }
}